package images;

import org.newdawn.slick.opengl.Texture;

/**
 *
 * @author Luan
 */
public class ComponentLoader {
    private static Texture imgComponents;
    private static ImageInfo[][] components;
    
    public static void load() {
        imgComponents = ImageManager.getTexture("components.png");
        
        components = new ImageInfo[4][3];
        float px = imgComponents.getWidth()/imgComponents.getImageWidth(), py = imgComponents.getHeight()/imgComponents.getImageHeight();
        for (int i = 0; i < components.length; i++)
            for (int j = 0; j < components[i].length; j++)
                components[i][j] = new ImageInfo(4*j, 4*i + (j==2?0:0), 4, 4, 0, px, py);
    }
    
    public static void drawBox(int c, int x, int y, int w, int h) {
        imgComponents.bind();
        
        //Desenhar os cantos
        draw(c, 0, x, y, 0);
        draw(c, 0, x + w - 4, y, 1);
        draw(c, 0, x + w - 4, y + h - 4, 2);
        draw(c, 0, x, y + h - 4, 3);
        
        //Desenhar as hastes
        draw(c, 1, x + 4, y, w - 8, 4, 0);
        draw(c, 1, x + w - h/2 + 2, y + h/2 - 2, h - 8, 4, 1);
        draw(c, 1, x + 4, y + h - 4, w - 8, 4, 2);
        draw(c, 1, x - h/2 + 6, y + h/2 - 2, h - 8, 4, 3);
        
        //Desenhar centro
        draw(c, 2, x + 4, y + 4, w - 8, h - 8, 0);
    }
    
    public static void draw(int c1, int c2, int x, int y, int a) {
        draw(c1, c2, x, y, 4, 4, a);
    }
    
    public static void draw(int c1, int c2, int x, int y, int w, int h, int a) {
        components[c1][c2].draw(x, y, w, h, (float) 90*a);
    }
}